﻿using System;
using System.Web.UI;
using System.Windows.Forms;

namespace com.orange.examination
{
    public partial class WebForm15 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

            IdentifyingCode.Text = RandomBuild.Random();

            if (Page.IsPostBack)
            {
                this.txtPwd.Attributes.Add("value", this.txtPwd.Text);
            }
            else
            {   
            }
        }

        protected void Btnlogin_Click(object sender, EventArgs e)
        {

            if (txtCode.Text.Trim().ToString() != IdentifyingCode.Text.Trim().ToString())
            {
                Response.Write("<script>window.alert('验证码错误！');</script>");
            }
            else
            {
                if (this.ddlstatus.SelectedValue == "学生")
                {
                    if (BaseClass.CheckStudent(txtNum.Text.Trim(), txtPwd.Text.Trim()))
                    {
                        Session["ID"] = txtNum.Text;
                        Response.Redirect("../Student/studentexam.aspx");
                    }
                    else
                    {
                        Response.Write("<script>window.alert('您不是学生或者用户名和密码错误！');</script>");
                    }

                }

                if (this.ddlstatus.SelectedValue == "教师")
                {
                    if (BaseClass.CheckTeacher(txtNum.Text.Trim(), txtPwd.Text.Trim()))
                    {
                        Session["teacher"] = txtNum.Text;
                        Response.Redirect("../Teacher/TeacherManage.aspx");
                    }
                    else
                    {
                        Response.Write("<script>window.alert('您不是教师或者用户名和密码错误！');</script>");
                    }

                }

                if (this.ddlstatus.SelectedValue == "管理员")
                {
                    if (BaseClass.CheckAdmin(txtNum.Text.Trim(), txtPwd.Text.Trim()))
                    {
                        Session["admin"] = txtNum.Text;
                        Response.Redirect("../Admin/AdminManage.aspx");
                    }
                    else
                    {
                        Response.Write("<script>window.alert('您不是管理员或者用户名和密码错误！');</script>");
                    }

                }
            }

        }


        protected void Btnconcle_Click(object sender, EventArgs e)
        {
            txtCode.Text = "";
            txtNum.Text = "";
            txtPwd.Text = "";
        }

        protected void Register_Click(object sender, EventArgs e)
        {
            Response.Redirect("Register.aspx");
            
        }

    }
}